from django.contrib.auth.models import AbstractUser
from django.db import models


class User(AbstractUser):
    """
    TestHub测试平台的自定义用户模型
    
    该模型扩展了Django的AbstractUser，增加了测试平台所需的额外字段
    """
    # 测试平台的用户类型选择
    USER_TYPE_CHOICES = (
        ('ADMIN', '系统管理员'),
        ('TESTER', '测试员'),
        ('DEVELOPER', '开发人员'),
        ('MANAGER', '测试管理员'),
        ('VIEWER', '报告查看者'),
    )
    
    user_type = models.CharField(
        max_length=20,
        choices=USER_TYPE_CHOICES,
        default='ADMIN',
        verbose_name='用户类型'
    )
    
    phone_number = models.CharField(
        max_length=11,
        null=True,
        blank=True,
        unique=True,
        verbose_name='手机号码'
    )
    
    department = models.ForeignKey(
        'department.Department',
        on_delete=models.SET_NULL,
        null=True,
        blank=True,
        verbose_name='所属部门'
    )
    
    employee_id = models.CharField(
        max_length=20,
        null=True,
        blank=True,
        verbose_name='员工编号'
    )
    
    # 用户头像
    avatar = models.URLField(
        max_length=255,
        null=True,
        blank=True,
        verbose_name='用户头像'
    )
    
    # 测试平台特定的指标跟踪
    tests_created = models.IntegerField(default=0, verbose_name='创建的测试数')
    tests_executed = models.IntegerField(default=0, verbose_name='执行的测试数')
    
    class Meta:
        verbose_name = '用户'
        verbose_name_plural = '用户'
        db_table = 'tb_user'
        
    def __str__(self):
        return f"{self.username} ({self.get_user_type_display()})"
